/**
 * 
 */
package com.postek.coyote.postekwifi;

import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Spinner;
import android.widget.Toast;

import com.postek.cdf.CDFPTKAndroid;

/**
 * @author yrwang
 *
 */
public class RFIDLockActivity extends AppCompatActivity {
	
	private CDFPTKAndroid cdf = MainActivity.cdf;
	
	private Button btnPrint = null;
	private Button btnCancel = null;
	
	private Spinner sp_RZ1 = null;
	private Spinner sp_RZ2 = null;
	private EditText et_RZS = null;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		setContentView(R.layout.rfid_lock);
		
		btnPrint = (Button) findViewById(R.id.btn_printRZ_print);
		btnCancel = (Button) findViewById(R.id.btn_printRZ_cancel);
		sp_RZ1 = (Spinner) findViewById(R.id.sp_rfid_RZ1);
		sp_RZ2 = (Spinner) findViewById(R.id.sp_rfid_RZ2);
		et_RZS = (EditText) findViewById(R.id.et_rfid_RZS);
		
		btnCancel.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				finish();
			}
		});
		
		btnPrint.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				int iRZ1 = sp_RZ1.getSelectedItemPosition();
				int iRZ2 = sp_RZ2.getSelectedItemPosition();
				String iRZS = et_RZS.getText().toString();
				
				int nReturn = cdf.PTK_SetRFLabelPWAndLockRFLabel(iRZ1, iRZ2, iRZS);
				
				if (nReturn == 0) {
					Toast.makeText(RFIDLockActivity.this,  R.string.setting_success, Toast.LENGTH_SHORT).show();
					finish();
				} else {
					Toast.makeText(RFIDLockActivity.this,  R.string.setting_fail, Toast.LENGTH_SHORT).show();
				}
			}
		});
		
	}
}
